/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#if defined(_WIN32)

#include "zobjects_system.h"

struct ZlangDirectProperty_regedit
{
	int		dummy ;
} ;

ZlangInvokeFunction ZlangInvokeFunction_regedit_CreateKeys_ulong_string_string;
int ZlangInvokeFunction_regedit_CreateKeys_ulong_string_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject			*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject			*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject			*in3 = GetInputParameterInLocalObjectStack(rt,3) ;
	struct ZlangObject			*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	uint64_t				root_hkey ;
	char					*keys = NULL ;
	char					*keys_value = NULL ;
	int32_t					keys_value_len ;
	HKEY					reghkey_keys ;
	char					*convert_keys_value = NULL ;
	LSTATUS					lsret ;
	int					nret = 0 ;
	
	CallRuntimeFunction_ulong_GetULongValue( rt , in1 , & root_hkey );
	CallRuntimeFunction_string_GetStringValue( rt , in2 , & keys , NULL );
	if( IsObjectPropertiesEntityNotNull(in3) )
	{
		CallRuntimeFunction_string_GetStringValue( rt , in3 , & keys_value , & keys_value_len );
	}
	
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegCreateKey('%s')" , keys )
	lsret = RegCreateKey( (HKEY)root_hkey , keys , & reghkey_keys ) ;
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegCreateKey('%s') return[%d]" , keys , lsret )
	if( lsret != ERROR_SUCCESS )
	{
		CallRuntimeFunction_bool_SetBoolValue( rt , out1 , FALSE );
		if( STRICMP( GetRuntimeCharsetString(rt) , != , WBYTE_CHARSET_GB18030_STR ) )
			free( convert_keys_value );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGCREATEKEY_FAILED );
	}

	if( IsObjectPropertiesEntityNotNull(in3) )
	{
		if( STRICMP( GetRuntimeCharsetString(rt) , != , WBYTE_CHARSET_GB18030_STR ) )
		{
			nret = ConvertStringEncoding( GetRuntimeCharsetString(rt) , WBYTE_CHARSET_GB18030_STR , keys_value , keys_value_len , & convert_keys_value , NULL , NULL ) ;
			if( nret )
			{
				TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "ConvertStringEncoding failed[%d]" , nret )
				return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_CONVERTSTRINGENCODING );
			}
		}
		else
		{
			convert_keys_value = keys_value ;
		}

		TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegSetValue('%s','%s')" , keys , convert_keys_value )
		lsret = RegSetValue( reghkey_keys , NULL , REG_SZ , convert_keys_value , (DWORD)strlen(convert_keys_value) ) ;
		TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegSetValue('%s','%s') return[%d]" , keys , convert_keys_value , lsret )
		if( lsret != ERROR_SUCCESS )
		{
			CallRuntimeFunction_bool_SetBoolValue( rt , out1 , FALSE );
			if( STRICMP( GetRuntimeCharsetString(rt) , != , WBYTE_CHARSET_GB18030_STR ) )
				free( convert_keys_value );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGSETVALUE_FAILED );
		}

		if( STRICMP( GetRuntimeCharsetString(rt) , != , WBYTE_CHARSET_GB18030_STR ) )
			free( convert_keys_value );
	}

	CallRuntimeFunction_bool_SetBoolValue( rt , out1 , TRUE );
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_regedit_CreateKey_ulong_string_string_string;
int ZlangInvokeFunction_regedit_CreateKey_ulong_string_string_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject			*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject			*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject			*in3 = GetInputParameterInLocalObjectStack(rt,3) ;
	struct ZlangObject			*in4 = GetInputParameterInLocalObjectStack(rt,4) ;
	struct ZlangObject			*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	uint64_t				root_hkey ;
	char					*keys = NULL ;
	char					*key = NULL ;
	char					*key_value = NULL ;
	int32_t					key_value_len ;
	char					*convert_key_value = NULL ;
	HKEY					reghkey_keys ;
	LSTATUS					lsret ;
	int					nret = 0 ;

	CallRuntimeFunction_ulong_GetULongValue( rt , in1 , & root_hkey );
	CallRuntimeFunction_string_GetStringValue( rt , in2 , & keys , NULL );
	CallRuntimeFunction_string_GetStringValue( rt , in3 , & key , NULL );
	if( IsObjectPropertiesEntityNotNull(in4) )
	{
		CallRuntimeFunction_string_GetStringValue( rt , in4 , & key_value , & key_value_len );
	}
	
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegOpenKey('%s')" , keys )
	lsret = RegOpenKey( (HKEY)root_hkey , keys , & reghkey_keys ) ;
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegOpenKey('%s') return[%d]" , keys , lsret )
	if( lsret != ERROR_SUCCESS )
	{
		CallRuntimeFunction_bool_SetBoolValue( rt , out1 , FALSE );
		if( STRICMP( GetRuntimeCharsetString(rt) , != , WBYTE_CHARSET_GB18030_STR ) )
			free( convert_key_value );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGOPENKEY_FAILED );
	}

	if( IsObjectPropertiesEntityNotNull(in4) )
	{
		if( STRICMP( GetRuntimeCharsetString(rt) , != , WBYTE_CHARSET_GB18030_STR ) )
		{
			nret = ConvertStringEncoding( GetRuntimeCharsetString(rt) , WBYTE_CHARSET_GB18030_STR , key_value , key_value_len , & convert_key_value , NULL , NULL ) ;
			if( nret )
			{
				TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "ConvertStringEncoding failed[%d]" , nret )
				return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_CONVERTSTRINGENCODING );
			}
		}
		else
		{
			convert_key_value = key_value ;
		}

		TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegSetKeyValue('%s','%s','%s')" , keys , key , convert_key_value )
		lsret = RegSetKeyValue( reghkey_keys , NULL , key , REG_SZ , convert_key_value , (DWORD)strlen(convert_key_value) ) ;
		TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegSetKeyValue('%s','%s','%s') return[%d]" , keys , key , convert_key_value , lsret )
		if( lsret != ERROR_SUCCESS )
		{
			CallRuntimeFunction_bool_SetBoolValue( rt , out1 , FALSE );
			if( STRICMP( GetRuntimeCharsetString(rt) , != , WBYTE_CHARSET_GB18030_STR ) )
				free( convert_key_value );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGSETKEYVALUE_FAILED );
		}

		if( STRICMP( GetRuntimeCharsetString(rt) , != , WBYTE_CHARSET_GB18030_STR ) )
			free( convert_key_value );
	}

	CallRuntimeFunction_bool_SetBoolValue( rt , out1 , TRUE );
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_regedit_CreateKey_ulong_string_string_int;
int ZlangInvokeFunction_regedit_CreateKey_ulong_string_string_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject			*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject			*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject			*in3 = GetInputParameterInLocalObjectStack(rt,3) ;
	struct ZlangObject			*in4 = GetInputParameterInLocalObjectStack(rt,4) ;
	struct ZlangObject			*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	uint64_t				root_hkey ;
	char					*keys = NULL ;
	char					*key = NULL ;
	int32_t					key_value ;
	HKEY					reghkey_keys ;
	DWORD					key_value_dw ;
	LSTATUS					lsret ;
	
	CallRuntimeFunction_ulong_GetULongValue( rt , in1 , & root_hkey );
	CallRuntimeFunction_string_GetStringValue( rt , in2 , & keys , NULL );
	CallRuntimeFunction_string_GetStringValue( rt , in3 , & key , NULL );
	if( IsObjectPropertiesEntityNotNull(in4) )
	{
		CallRuntimeFunction_int_GetIntValue( rt , in4 , & key_value ); key_value_dw = key_value ;
	}
	
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegOpenKey('%s')" , keys )
	lsret = RegOpenKey( (HKEY)root_hkey , keys , & reghkey_keys ) ;
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegOpenKey('%s') return[%d]" , keys , lsret )
	if( lsret != ERROR_SUCCESS )
	{
		CallRuntimeFunction_bool_SetBoolValue( rt , out1 , FALSE );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGOPENKEY_FAILED );
	}

	if( IsObjectPropertiesEntityNotNull(in4) )
	{
		TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegSetKeyValue('%s','%s',%d)" , keys , key , key_value_dw )
		lsret = RegSetKeyValue( reghkey_keys , NULL , key , REG_SZ , & key_value_dw , sizeof(key_value_dw) ) ;
		TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegSetKeyValue('%s','%s',%d) return[%d]" , keys , key , key_value_dw , lsret )
		if( lsret != ERROR_SUCCESS )
		{
			CallRuntimeFunction_bool_SetBoolValue( rt , out1 , FALSE );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGSETKEYVALUE_FAILED );
		}
	}

	CallRuntimeFunction_bool_SetBoolValue( rt , out1 , TRUE );
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_regedit_QueryKeys_ulong_string;
int ZlangInvokeFunction_regedit_QueryKeys_ulong_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject			*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject			*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject			*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	uint64_t				root_hkey ;
	char					*keys = NULL ;
	HKEY					reghkey_keys ;
	DWORD					keys_value_len ;
	DWORD					keys_value_size ;
	char					*keys_value = NULL ;
	char					*convert_keys_value = NULL ;
	LSTATUS					lsret ;
	int					nret = 0 ;
	
	CallRuntimeFunction_ulong_GetULongValue( rt , in1 , & root_hkey );
	CallRuntimeFunction_string_GetStringValue( rt , in2 , & keys , NULL );
	
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegOpenKey('%s')" , keys )
	lsret = RegOpenKey( (HKEY)root_hkey , keys , & reghkey_keys ) ;
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegOpenKey('%s') return[%d]" , keys , lsret )
	if( lsret != ERROR_SUCCESS )
	{
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGOPENKEY_FAILED );
	}

	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegQueryValue('%s')" , keys )
	lsret = RegQueryValue( reghkey_keys , NULL , NULL , & keys_value_len ) ;
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegQueryValue('%s') return[%d]" , keys , lsret )
	if( lsret != ERROR_SUCCESS )
	{
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGSETKEYVALUE_FAILED );
	}

	keys_value_size = keys_value_len + 1 ;
	keys_value = (char*)malloc( keys_value_size ) ;
	if( keys_value == NULL )
	{
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_ALLOC_FAILED );
	}
	memset( keys_value , 0x00 , keys_value_size );

	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegQueryValue('%s')" , keys )
	lsret = RegQueryValue( reghkey_keys , NULL , keys_value , & keys_value_size ) ;
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegQueryValue('%s') return[%d]" , keys , lsret )
	if( lsret != ERROR_SUCCESS )
	{
		UnreferObject( rt , out1 );
		free( keys_value );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGSETKEYVALUE_FAILED );
	}

	if( STRICMP( GetRuntimeCharsetString(rt) , != , WBYTE_CHARSET_GB18030_STR ) )
	{
		nret = ConvertStringEncoding( WBYTE_CHARSET_GB18030_STR , GetRuntimeCharsetString(rt) , keys_value , keys_value_len , & convert_keys_value , NULL , NULL ) ;
		if( nret )
		{
			TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "ConvertStringEncoding failed[%d]" , nret )
			free( keys_value );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_CONVERTSTRINGENCODING );
		}
	}
	else
	{
		convert_keys_value = keys_value ;
	}

	CallRuntimeFunction_string_SetStringValue( rt , out1 , convert_keys_value , STRLEN_OF_STRING );

	free( keys_value );
	if( STRICMP( GetRuntimeCharsetString(rt) , != , WBYTE_CHARSET_GB18030_STR ) )
	{
		free( convert_keys_value );
	}

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_regedit_QueryKey_ulong_string_string;
int ZlangInvokeFunction_regedit_QueryKey_ulong_string_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject			*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject			*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject			*in3 = GetInputParameterInLocalObjectStack(rt,3) ;
	struct ZlangObject			*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	uint64_t				root_hkey ;
	char					*keys = NULL ;
	char					*key = NULL ;
	HKEY					reghkey_keys ;
	DWORD					key_type ;
	DWORD					key_value_len ;
	DWORD					key_value_size ;
	char					*key_value = NULL ;
	char					*convert_keys_value = NULL ;
	LSTATUS					lsret ;
	int					nret = 0 ;
	
	CallRuntimeFunction_ulong_GetULongValue( rt , in1 , & root_hkey );
	CallRuntimeFunction_string_GetStringValue( rt , in2 , & keys , NULL );
	CallRuntimeFunction_string_GetStringValue( rt , in3 , & key , NULL );
	
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegOpenKey('%s')" , keys )
	lsret = RegOpenKey( (HKEY)root_hkey , keys , & reghkey_keys ) ;
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegOpenKey('%s') return[%d]" , keys , lsret )
	if( lsret != ERROR_SUCCESS )
	{
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGOPENKEY_FAILED );
	}

	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegQueryValue('%s','%s')" , keys , key )
	lsret = RegQueryValueEx( reghkey_keys , key , NULL , & key_type , NULL , & key_value_len ) ;
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegQueryValue('%s','%s') return[%d]" , keys , key , lsret )
	if( lsret != ERROR_SUCCESS )
	{
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGSETKEYVALUE_FAILED );
	}

	if( key_type == REG_SZ )
	{
		nret = InitObject( rt , out1 , NULL , GetObjectDirectFunctions(GetStringObjectInRuntimeObjectsHeap(rt)) , 0 ) ;
		if( nret )
		{
			UnreferObject( rt , out1 );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_INIT_OBJECT_FAILED );
		}

		key_value_size = key_value_len + 1 ;
		key_value = (char*)malloc( key_value_size ) ;
		if( key_value == NULL )
		{
			UnreferObject( rt , out1 );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_ALLOC_FAILED );
		}
		memset( key_value , 0x00 , key_value_size );

		TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegQueryValue('%s','%s')" , keys , key )
		lsret = RegQueryValueEx( reghkey_keys , key , NULL , NULL , key_value , & key_value_size ) ;
		TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegQueryValue('%s','%s') return[%d]" , keys , key , lsret )
		if( lsret != ERROR_SUCCESS )
		{
			UnreferObject( rt , out1 );
			free( key_value );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGQUERYVALUE_FAILED );
		}
		
		if( STRICMP( GetRuntimeCharsetString(rt) , != , WBYTE_CHARSET_GB18030_STR ) )
		{
			nret = ConvertStringEncoding( WBYTE_CHARSET_GB18030_STR , GetRuntimeCharsetString(rt) , key_value , key_value_len , & convert_keys_value , NULL , NULL ) ;
			if( nret )
			{
				TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "ConvertStringEncoding failed[%d]" , nret )
				free( key_value );
				return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_CONVERTSTRINGENCODING );
			}
		}
		else
		{
			convert_keys_value = key_value ;
		}

		CallRuntimeFunction_string_SetStringValue( rt , out1 , convert_keys_value , STRLEN_OF_STRING );

		free( key_value );
		if( STRICMP( GetRuntimeCharsetString(rt) , != , WBYTE_CHARSET_GB18030_STR ) )
		{
			free( convert_keys_value );
		}
	}
	else if( key_type == REG_DWORD )
	{
		DWORD	key_value_dw ;

		nret = InitObject( rt , out1 , NULL , GetObjectDirectFunctions(GetIntObjectInRuntimeObjectsHeap(rt)) , 0 ) ;
		if( nret )
		{
			UnreferObject( rt , out1 );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_INIT_OBJECT_FAILED );
		}

		TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegQueryValue('%s','%s')" , keys , key )
		lsret = RegQueryValueEx( reghkey_keys , key , NULL , NULL , (LPBYTE) & key_value_dw , NULL ) ;
		TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegQueryValue('%s','%s') return[%d]" , keys , key , lsret )
		if( lsret != ERROR_SUCCESS )
		{
			UnreferObject( rt , out1 );
			return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGQUERYVALUE_FAILED );
		}

		CallRuntimeFunction_int_SetIntValue( rt , out1 , key_value_dw );
	}
	else
	{
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_KEY_TYPE_NOT_SUPPORTED );
	}

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_regedit_DeleteKeys_ulong_string;
int ZlangInvokeFunction_regedit_DeleteKeys_ulong_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject			*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject			*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject			*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	uint64_t				root_hkey ;
	char					*keys = NULL ;
	LSTATUS					lsret ;
	
	CallRuntimeFunction_ulong_GetULongValue( rt , in1 , & root_hkey );
	CallRuntimeFunction_string_GetStringValue( rt , in2 , & keys , NULL );
	
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegDeleteKey('%s')" , keys )
	lsret = RegDeleteKey( (HKEY)root_hkey , keys ) ;
	TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "RegDeleteKey('%s') return[%d]" , keys , lsret )
	if( lsret != ERROR_SUCCESS )
	{
		CallRuntimeFunction_bool_SetBoolValue( rt , out1 , FALSE );
		return ThrowErrorException( rt , EXCEPTION_CODE_GENERAL , EXCEPTION_MESSAGE_REGDELETEKEY_FAILED );
	}

	CallRuntimeFunction_bool_SetBoolValue( rt , out1 , TRUE );
	return 0;
}

ZlangCreateDirectPropertyFunction ZlangCreateDirectProperty_regedit;
void *ZlangCreateDirectProperty_regedit( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_regedit	*regedit_prop = NULL ;
	
	regedit_prop = (struct ZlangDirectProperty_regedit *)ZLMALLOC( sizeof(struct ZlangDirectProperty_regedit) ) ;
	if( regedit_prop == NULL )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_ALLOC , "alloc memory for entity" )
		return NULL;
	}
	memset( regedit_prop , 0x00 , sizeof(struct ZlangDirectProperty_regedit) );
	
	return regedit_prop;
}

ZlangDestroyDirectPropertyFunction ZlangDestroyDirectProperty_regedit;
void ZlangDestroyDirectProperty_regedit( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_regedit	*regedit_direct_prop = GetObjectDirectProperty(obj) ;
	
	ZLFREE( regedit_direct_prop );
	
	return;
}

ZlangSummarizeDirectPropertySizeFunction ZlangSummarizeDirectPropertySize_regedit;
void ZlangSummarizeDirectPropertySize_regedit( struct ZlangRuntime *rt , struct ZlangObject *obj , size_t *summarized_obj_size , size_t *summarized_direct_prop_size )
{
	SUMMARIZE_SIZE( summarized_direct_prop_size , sizeof(struct ZlangDirectProperty_regedit) )
	return;
}

static struct ZlangDirectFunctions direct_funcs_regedit =
	{
		ZLANG_OBJECT_regedit , /* char *ancestor_name */
		
		ZlangCreateDirectProperty_regedit , /* ZlangCreateDirectPropertyFunction *create_entity_func */
		ZlangDestroyDirectProperty_regedit , /* ZlangDestroyDirectPropertyFunction *destroy_entity_func */
		
		NULL , /* ZlangFromCharPtrFunction *from_char_ptr_func */
		NULL , /* ZlangToStringFunction *to_string_func */
		NULL , /* ZlangFromDataPtrFunction *from_data_ptr_func */
		NULL , /* ZlangGetDataPtrFunction *get_data_ptr_func */
		
		NULL , /* ZlangOperatorFunction *oper_PLUS_func */
		NULL , /* ZlangOperatorFunction *oper_MINUS_func */
		NULL , /* ZlangOperatorFunction *oper_MUL_func */
		NULL , /* ZlangOperatorFunction *oper_DIV_func */
		NULL , /* ZlangOperatorFunction *oper_MOD_func */
		
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NEGATIVE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NOT_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_BIT_REVERSE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_PLUS_PLUS_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_MINUS_MINUS_func */
		
		NULL , /* ZlangCompareFunction *comp_EGUAL_func */
		NULL , /* ZlangCompareFunction *comp_NOTEGUAL_func */
		NULL , /* ZlangCompareFunction *comp_LT_func */
		NULL , /* ZlangCompareFunction *comp_LE_func */
		NULL , /* ZlangCompareFunction *comp_GT_func */
		NULL , /* ZlangCompareFunction *comp_GE_func */
		
		NULL , /* ZlangLogicFunction *logic_AND_func */
		NULL , /* ZlangLogicFunction *logic_OR_func */
		
		NULL , /* ZlangLogicFunction *bit_AND_func */
		NULL , /* ZlangLogicFunction *bit_XOR_func */
		NULL , /* ZlangLogicFunction *bit_OR_func */
		NULL , /* ZlangLogicFunction *bit_MOVELEFT_func */
		NULL , /* ZlangLogicFunction *bit_MOVERIGHT_func */
		
		ZlangSummarizeDirectPropertySize_regedit , /* ZlangSummarizeDirectPropertySizeFunction *summarize_direct_prop_size_func */
	} ;

ZlangImportObjectFunction ZlangImportObject_regedit;
struct ZlangObject *ZlangImportObject_regedit( struct ZlangRuntime *rt )
{
	struct ZlangObject	*obj = NULL ;
	struct ZlangObject	*prop = NULL ;
	struct ZlangFunction	*func = NULL ;
	int			nret = 0 ;
	
	nret = ImportObject( rt , & obj , ZLANG_OBJECT_regedit , & direct_funcs_regedit , sizeof(struct ZlangDirectFunctions) , NULL ) ;
	if( nret )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_LINK_FUNC_TO_ENTITY , "import object to global objects heap" )
		return NULL;
	}
	
	prop = AddPropertyInObject( rt , obj , GetULongObjectInRuntimeObjectsHeap(rt) , "HKEY_CLASSES_ROOT") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_ulong_SetULongValue( rt , prop , (uint64_t)HKEY_CLASSES_ROOT );
	SetConstantObject( prop );
	
	prop = AddPropertyInObject( rt , obj , GetULongObjectInRuntimeObjectsHeap(rt) , "HKEY_CURRENT_USER") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_ulong_SetULongValue( rt , prop , (uint64_t)HKEY_CURRENT_USER );
	SetConstantObject( prop );
	
	prop = AddPropertyInObject( rt , obj , GetULongObjectInRuntimeObjectsHeap(rt) , "HKEY_LOCAL_MACHINE") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_ulong_SetULongValue( rt , prop , (uint64_t)HKEY_LOCAL_MACHINE );
	SetConstantObject( prop );
	
	prop = AddPropertyInObject( rt , obj , GetULongObjectInRuntimeObjectsHeap(rt) , "HKEY_USERS") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_ulong_SetULongValue( rt , prop , (uint64_t)HKEY_USERS );
	SetConstantObject( prop );
	
	prop = AddPropertyInObject( rt , obj , GetULongObjectInRuntimeObjectsHeap(rt) , "HKEY_CURRENT_CONFIG") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_ulong_SetULongValue( rt , prop , (uint64_t)HKEY_CURRENT_CONFIG );
	SetConstantObject( prop );
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_regedit_CreateKeys_ulong_string_string , ZLANG_OBJECT_bool , "CreateKeys" , ZLANG_OBJECT_ulong,NULL , ZLANG_OBJECT_string,NULL , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_regedit_CreateKey_ulong_string_string_string , ZLANG_OBJECT_bool , "CreateKey" , ZLANG_OBJECT_ulong,NULL , ZLANG_OBJECT_string,NULL , ZLANG_OBJECT_string,NULL , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_regedit_CreateKey_ulong_string_string_int , ZLANG_OBJECT_bool , "CreateKey" , ZLANG_OBJECT_ulong,NULL , ZLANG_OBJECT_string,NULL , ZLANG_OBJECT_string,NULL , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_regedit_QueryKeys_ulong_string , ZLANG_OBJECT_string , "QueryKeys" , ZLANG_OBJECT_ulong,NULL , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_regedit_QueryKey_ulong_string_string , ZLANG_OBJECT_object , "QueryKey" , ZLANG_OBJECT_ulong,NULL , ZLANG_OBJECT_string,NULL , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_regedit_DeleteKeys_ulong_string , ZLANG_OBJECT_bool , "DeleteKeys" , ZLANG_OBJECT_ulong,NULL , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_regedit_DeleteKeys_ulong_string , ZLANG_OBJECT_bool , "DeleteKey" , ZLANG_OBJECT_ulong,NULL , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	return obj ;
}

#endif
